//============================================//
//  Linked List Example
//  by Drake Bissett - 2013
//  --------------------------
//  Simple demo of a linked list:
//  -Each node contains a pointer to the
//  next node in the series.
//  --------------------------
//  dsbissett@gmail.com
//  w32reverse@gmail.com
//============================================//
#include <cstdlib>
#include <iostream>

#include "list.h"

using namespace std;

List::List()
{
	head = NULL;
	curr = NULL;
	temp = NULL;
}

void List::AddNode(int addData)
{
	nodePtr n = new node;
	n->Next = NULL;
	n->data = addData;

	if (head !=	NULL)
	{
		curr = head;
		while (curr->Next != NULL)
		{
			curr = curr->Next;
		}

		curr->Next = n;
	}
	else
	{ head = n; }
}

void List::DeleteNode(int delData)
{
	nodePtr delPtr = NULL;
	temp = head;
	curr = head;
	while (curr != NULL && curr->data != delData)
	{
		temp = curr;
		curr = curr->Next;
	}
	if (curr ==	NULL)
	{
		cout << delData << " was not in the list!\n";
		delete delPtr;
	}
	else
	{
		delPtr = curr;
		curr = curr->Next;
		temp->Next = curr;
		delete delPtr;
		cout << "The value " << delData << " was deleted!\n";
	}
}

void List::PrintList()
{
	curr = head;
	while (curr != NULL)
	{
		cout << curr->data << endl;
		curr = curr->Next;
	}
}